package com.ziyucoding.springboot.labs.lab4.concurrentdemo.example.singleton;

import com.ziyucoding.springboot.labs.lab4.concurrentdemo.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

/**
 * 单例模式
 * 饿汉模式：单例实例在在类装载时进行创建
 *
 * @author ziyucoding
 * @date 2022-10-26
 **/
@ThreadSafe
public class SingletonExample6 {

    /**
     * 单例
     */
    private static SingletonExample6 instance = null;

    static {
        instance = new SingletonExample6();
    }

    private SingletonExample6() {

    }

    /**
     * 获取实例
     *
     * @param
     * @return SingletonExample6
     **/
    public static SingletonExample6 getInstance() {
        return instance;
    }

    public static void main(String[] args) {
        System.out.println(getInstance().hashCode());
        System.out.println(getInstance().hashCode());
    }
}
